package com.huabo.utils;

import java.io.Serializable;

public class Response implements Serializable {

    private int code;

    private String message;

    private Object data;

    public Response() {
    }

    public Response(ReturnCode returnCode, Object data) {
        this.code = returnCode.code();
        this.message = returnCode.message();
        this.data = data;
    }

    public Response(Object data) {
        this(CommonReturnCode.SUCCESS, data);
    }

    public Response(ReturnCode returnCode) {
        this(returnCode, null);
    }

    public Response(ReturnCode returnCode, String message) {
        this.code = returnCode.code();
        this.message = message != null ? message : returnCode.message();
    }

    public Response(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Response(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return CommonReturnCode.SUCCESS.code() == this.code;
    }

    @Override
    public String toString() {
        return String.format("Response [code=%d, message=%s, data=%s]", code, message, data == null ? data : data.toString());
    }

}
